﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace MvvmEx.Converter
{
    /// <summary>
    /// 枚举转Bool转换器
    /// </summary>
    public class EnumToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value != null && value.ToString().Equals(parameter.ToString());
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value != null && value.Equals(true) ? Enum.Parse(targetType, parameter.ToString()) : Binding.DoNothing;
        }
    }
}